package com.ruoyi.algorithm.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.algorithm.entity.UserTableStruct;
import com.ruoyi.algorithm.mapper.UserTableStructMapper;
import com.beihu.sightplus.common.repository.BaseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：yanfa-03
 * @date ：Created in 2021/7/12/11:47
 * @description ：
 * @version: 1.0
 */
@Service
public class UserTableStructRepository extends BaseRepository<UserTableStructMapper, UserTableStruct> {

    @Autowired
    UserTableStructMapper userTableStructMapper;

    /**
     * 根据用户id与struct表id获取user_struct关联表数据
     *
     * @param userId   用户id
     * @param structId 结构表id
     * @return user_struct数据列表
     */
    public UserTableStruct getByUserIdAndStructId(Long userId, Long structId) {
        return userTableStructMapper.selectOne(
                Wrappers.lambdaQuery(UserTableStruct.class)
                        .eq(UserTableStruct::getUserId, userId)
                        .eq(UserTableStruct::getTableStructId, structId)
        );
    }

    /**
     * 根据用户id获取关系列表
     *
     * @param userId 用户id
     * @return 关系列表
     */
    public List<UserTableStruct> getListByUserId(Long userId) {
        return userTableStructMapper.selectList(Wrappers.lambdaQuery(UserTableStruct.class).eq(UserTableStruct::getUserId, userId));
    }
}
